/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_W25Q64.h
 *
 *  Created on: 2022年6月23日
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_W25Q64_H_
#define PERIPHERAL_LAYER_INC_LOS_W25Q64_H_

#include "LOS_SYS.h"

//W25Q64指令表
#define W25Q64_Write_Enable						          0x06
#define W25Q64_Write_Disable                              0x04
#define W25Q64_Read_Status_register_1				      0x05
#define W25Q64_Read_Status_register_2				      0x35
#define W25Q64_Write_Status_register				      0x01
#define W25Q64_Page_Program							      0x02
#define W25Q64_Quad_Page_Program				          0x32
#define W25Q64_Block_Erase_64KB						      0xD8
#define W25Q64_Block_Erase_32KB						      0x52
#define W25Q64_Sector_Erase_4KB						      0x20
#define W25Q64_Chip_Erase							      0xC7
#define W25Q64_Erase_Suspend					          0x75
#define W25Q64_Erase_Resume							      0x7A
#define W25Q64_Power_down							      0xB9
#define W25Q64_High_Performance_Mode				      0xA3
#define W25Q64_Continuous_Read_Mode_Reset			      0xFF
#define W25Q64_Release_Power_Down_HPM_Device_ID		      0xAB
#define W25Q64_Manufacturer_Device_ID				      0x90
#define W25Q64_Read_Uuique_ID						      0x4B
#define W25Q64_JEDEC_ID								      0x9F

#define W25Q64_Read_Data						          0x03
#define W25Q64_Fast_Read						          0x0B
#define W25Q64_Fast_Read_Dual_Output				      0x3B
#define W25Q64_Fast_Read_Dual_IO					      0xBB
#define W25Q64_Fast_Read_Quad_Output				      0x6B
#define W25Q64_Fast_Read_Quad_IO					      0xEB
#define W25Q64_Octal_Word_Read_Quad_IO				      0xE3

#define W25Q64_DUMMY_BYTE 0xFF

#define LOS_SPI_W25Q64 LOS_SPI_NUM3
#define CS_W25Q64 CS_0
#define CS_W25Q64_S CS_5

void LOS_W25Q64_ReadID(uint8_t* ID);
void LOS_W25Q64_WriteEnable();
void LOS_W25Q64_WriteDisable();
uint32_t LOS_W25Q64_WaitForBusyStatus();
void LOS_W25Q64_SectorErase(uint32_t Sector_Address);
void LOS_W25Q64_BlockErase(uint32_t Block_Address);
void LOS_W25Q64_ChipErase();
void LOS_W25Q64_PageWrite(uint32_t address, uint8_t *data, uint16_t dataSize);
void LOS_W25Q64_ReadData(uint32_t address, uint8_t *data, uint16_t dataSize);
void LOS_W25Q64S_WriteEnable();
void LOS_W25Q64S_WriteDisable();
uint32_t LOS_W25Q64S_WaitForBusyStatus();
void LOS_W25Q64S_SectorErase(uint32_t Sector_Address);
void LOS_W25Q64S_BlockErase(uint32_t Block_Address);
void LOS_W25Q64S_ChipErase();
void LOS_W25Q64S_PageWrite(uint32_t address, uint8_t *data, uint16_t dataSize);
void LOS_W25Q64S_ReadData(uint32_t address, uint8_t *data, uint16_t dataSize);

#endif /* PERIPHERAL_LAYER_INC_LOS_W25Q64_H_ */
